package options

import (
	"encoding/json"

	genericOpts "github.com/mars/internal/pkg/options"
	"github.com/mars/pkg/app"
)

// Options 是 Admin 的全部选项配置
type Options struct {
	GinOptions     *genericOpts.GinOptions     `json:"gin"       mapstructure:"gin"`
	LogOption      *genericOpts.LogOptions     `json:"log"       mapstructure:"log"`
	WxcloudOptions *genericOpts.WxCloudOptions `json:"wxcloud"   mapstructure:"wxcloud"`
}

func NewOptions() *Options {
	return &Options{
		GinOptions:     genericOpts.NewGinOptions(),
		LogOption:      genericOpts.NewLogOptions(),
		WxcloudOptions: genericOpts.NewWxCloudOptions(),
	}
}

func (o *Options) Flags() (fss app.NamedFlagSets) {
	o.GinOptions.AddFlags(fss.FlagSet("gin"))
	o.LogOption.AddFlags(fss.FlagSet("log"))
	o.WxcloudOptions.AddFlags(fss.FlagSet("wxcloud"))

	return fss
}

func (o *Options) String() string {
	data, _ := json.Marshal(o)

	return string(data)
}

func (o *Options) Validate() []error {
	var errors = []error{}
	errors = append(errors, o.GinOptions.Validate()...)
	errors = append(errors, o.LogOption.Validate()...)
	errors = append(errors, o.WxcloudOptions.Validate()...)
	return errors
}
